<?php

namespace app\api\controller;

use app\api\extend\Common;
use think\facade\Db;

class HomeExchanmall extends Common
{
    // 无需登录的接口,*表示全部
    protected $noNeedLogin = ['list'];
    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = [];

    public function list() {
        $result = [];
        $res = $this->model->list();
        $classif = Db::name('home_comclassif')->select();

        foreach ($res as $v1) {
           foreach ($classif as $k2 => $v2) {
                  if ($v2['id'] == $v1['classif_goods_id']) {
                     if (!isset($result[$k2])) {
                          $result[$k2] = ['classif_id'=>$v2['id'],'classif_name'=>$v2['name']];
                     }
                      $result[$k2]['list'][] = [
                        'id'=>$v1['id'],
                        'title'=>$v1['name'],
                        'price'=>$v1['price'],
                        'pic_image'=>$v1['pic_image'],
                      ];
                  }
              }   
        }
        return $this->return_msg(200,'获取成功',$result);
    }
}